<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            /* 能够让行内元素和行内块元素实现水平居中 */
            text-align: center;
        }

        .box span {
            display: inline-block;
        }

        .box1 {
            background: red;
            width: 50%;
            height: 100px;
            /* 块元素实现水平居中 */
            margin: auto;
        }
    </style>
</head>

<body>
    <!-- 实现行内元素居中方式 -->
    <div class="box">
        <span>123</span>
    </div>
    <div class="box1"></div>

</body>

</html>